package LeetCode.month04.day96;

import java.util.Arrays;

/**
 * @author 16778
 * @date 2025/11/5 10:34
 * @description
 */
public class No3010 {
    public int minimumCost(int[] nums) {
        int n = nums.length;
        int[] ints = Arrays.copyOfRange(nums, 1, n);
        Arrays.sort(ints);
        return nums[0]+ints[0]+ints[1];
    }
    public int minimumCost2(int[] nums) {
        int res = nums[0];
        int a1 = Integer.MAX_VALUE;
        int a2 = Integer.MAX_VALUE;
        for (int i = 1; i < nums.length; i++) {
            if(nums[i]<a1){
                a2 = a1;
                a1 = nums[i];
            }else if(nums[i]<a2){
                a2 = nums[i];
            }
        }
        return res+a1+a2;
    }
}
